package org.zkpk.spark;

import java.io.Serializable;
import scala.math.Ordered;

class serDemo implements Serializable {

    private static final long serialVersionUID = 5749943279909593929L;

    private Float humidity;
    private Integer IAQ;
    private Float temperature;

    public serDemo() {
        super();
    }

    public serDemo(Float humidity, Integer IAQ, Float temperature) {
        super();
        this.IAQ = IAQ;
        this.humidity = humidity;
        this.temperature = temperature;
    }

    public Integer getIAQ() {
        return IAQ;
    }

    public void setIAQ(Integer IAQ) {
        this.IAQ = IAQ;
    }

    public Float getHumidity() {
        return humidity;
    }

    public void setHumidity(Float humidity) {
        this.humidity = humidity;
    }

    public Float getTemperature() {
        return temperature;
    }

    public void setTemperature(Float temperature) {
        this.temperature = temperature;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }
}

public class SecondarySortKey implements Ordered<SecondarySortKey>, Serializable {

    private static final long serialVersionUID = 3702442700882342403L;

    private Float humidity;
    private Integer IAQ;
    private Float temperature;

    public SecondarySortKey() {
        super();
        // TODO Auto-generated constructor stub
    }

    public SecondarySortKey(Float humidity, Integer IAQ, Float temperature) {
        super();
        this.IAQ = IAQ;
        this.humidity = humidity;
        this.temperature = temperature;
    }

    public Integer getIAQ() {
        return IAQ;
    }

    public void setIAQ(Integer IAQ) {
        this.IAQ = IAQ;
    }

    public Float getHumidity() {
        return humidity;
    }

    public void setHumidity(Float humidity) {
        this.humidity = humidity;
    }

    public Float getTemperature() {
        return temperature;
    }

    public void setTemperature(Float temperature) {
        this.temperature = temperature;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

    @Override
    public boolean $greater(SecondarySortKey other) {
        if (IAQ > other.IAQ) {
            return true;
        } else if (IAQ == other.IAQ && humidity > other.humidity) {
            return true;
        } else if (IAQ == other.IAQ && humidity == other.humidity && temperature > other.temperature) {
            return true;
        }
        return false;
    }

    @Override
    public boolean $greater$eq(SecondarySortKey other) {
        if ($greater(other)) {
            return true;
        } else if (IAQ == other.IAQ && humidity == other.humidity && temperature == other.temperature) {
            return true;
        }
        return false;
    }

    @Override
    public boolean $less(SecondarySortKey other) {
        if (IAQ < other.IAQ) {
            return true;
        } else if (IAQ == other.IAQ && humidity < other.humidity) {
            return true;
        } else if (IAQ == other.IAQ && humidity == other.humidity && temperature < other.temperature) {
            return true;
        }
        return false;
    }

    @Override
    public boolean $less$eq(SecondarySortKey other) {
        if ($less(other)) {
            return true;
        } else if (IAQ == other.IAQ && humidity == other.humidity && temperature == other.temperature) {
            return true;
        }
        return false;
    }

    @Override
    public int compare(SecondarySortKey other) {
        if (IAQ - other.IAQ != 0) {
            return (int) (IAQ - other.IAQ);
        } else if (humidity - other.humidity != 0) {
            return Math.round(100 * (humidity - other.humidity));
        } else if (temperature - other.temperature != 0) {
            return Math.round(100 * (temperature - other.temperature));
        }
        return 0;
    }

    @Override
    public int compareTo(SecondarySortKey other) {
        if (IAQ - other.IAQ != 0) {
            return (int) (IAQ - other.IAQ);
        } else if (humidity - other.humidity != 0) {
            return Math.round(100 * (humidity - other.humidity));
        } else if (temperature - other.temperature != 0) {
            return Math.round(100 * (temperature - other.temperature));
        }
        return 0;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + Math.round(100 * humidity);
        result = prime * result + Math.round(100 * temperature);
        result = prime * result + (int) (IAQ);
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        SecondarySortKey other = (SecondarySortKey) obj;
        if (humidity != other.humidity)
            return false;
        if (temperature != other.temperature)
            return false;
        if (IAQ != other.IAQ)
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "SortResult： [IAQ： " + IAQ + ", 湿度：  " + humidity + ", 温度：" + temperature + "]";
    }
}